package com.ruoyi.teach.controller;

import com.ruoyi.teach.domain.SchoolDailyWork;
import com.ruoyi.teach.service.SchoolDailyWorkService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.constant.BusinessTypeEnum;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 工作记录Controller
 *
 * @author ning
 * @date 2022-01-15
 */
@RestController
@RequestMapping("/school/dailyWork")
public class SchoolDailyWorkController extends BaseController
{
    @Autowired
    private SchoolDailyWorkService schoolDailyWorkService;


    /**
     * 查询工作记录列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SchoolDailyWork SchoolDailyWork)
    {
        startPage();
        SchoolDailyWork.setDelFlag("0");
        List<SchoolDailyWork> list = schoolDailyWorkService.selectSchoolDailyWorkList(SchoolDailyWork);
        return getDataTable(list);
    }

    /**
     * 导出工作记录列表
     */
//    @PreAuthorize("@ss.hasPermi('cms:message:export')")
    @Log(title = "工作记录", businessType = BusinessTypeEnum.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SchoolDailyWork SchoolDailyWork)
    {
        List<SchoolDailyWork> list = schoolDailyWorkService.selectSchoolDailyWorkList(SchoolDailyWork);
        ExcelUtil<SchoolDailyWork> util = new ExcelUtil<SchoolDailyWork>(SchoolDailyWork.class);
        util.exportExcel(response, list, "工作记录数据");
    }

    /**
     * 获取工作记录详细信息
     */
//    @PreAuthorize("@ss.hasPermi('cms:message:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(schoolDailyWorkService.selectSchoolDailyWorkById(id));
    }

    /**
     * 新增工作记录
     */
//    @PreAuthorize("@ss.hasPermi('cms:message:add')")
    @Log(title = "工作记录", businessType = BusinessTypeEnum.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SchoolDailyWork SchoolDailyWork)
    {
        return toAjax(schoolDailyWorkService.insertSchoolDailyWork(SchoolDailyWork));
    }

    /**
     * 修改工作记录
     */
//    @PreAuthorize("@ss.hasPermi('cms:message:edit')")
    @Log(title = "工作记录", businessType = BusinessTypeEnum.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SchoolDailyWork SchoolDailyWork)
    {
        return toAjax(schoolDailyWorkService.updateSchoolDailyWork(SchoolDailyWork));
    }

    /**
     * 删除工作记录
     */
//    @PreAuthorize("@ss.hasPermi('cms:message:remove')")
    @Log(title = "工作记录", businessType = BusinessTypeEnum.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(schoolDailyWorkService.deleteSchoolDailyWorkByIds(ids));
    }
}
